package cc.zyjx.web.controller.school;

import cc.zyjx.common.annotation.Log;
import cc.zyjx.common.core.controller.BaseController;
import cc.zyjx.common.core.domain.AjaxResult;
import cc.zyjx.common.core.page.TableDataInfo;
import cc.zyjx.common.enums.BusinessType;
import cc.zyjx.common.utils.poi.ExcelUtil;
import cc.zyjx.school.domain.TrArchives;
import cc.zyjx.school.service.ITrArchivesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 学员档案Controller
 * 
 * @author 座山客
 * @date 2023-05-02
 */
@RestController
@RequestMapping("/school/archives")
public class TrArchivesController extends BaseController
{
    @Autowired
    private ITrArchivesService trArchivesService;

    /**
     * 查询学员档案列表
     */
    @PreAuthorize("@ss.hasPermi('school:archives:list')")
    @GetMapping("/list")
    public TableDataInfo list(TrArchives trArchives)
    {
        startPage();
        List<TrArchives> list = trArchivesService.selectTrArchivesList(trArchives);
        return getDataTable(list);
    }

    /**
     * 导出学员档案列表
     */
    @PreAuthorize("@ss.hasPermi('school:archives:export')")
    @Log(title = "学员档案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TrArchives trArchives)
    {
        List<TrArchives> list = trArchivesService.selectTrArchivesList(trArchives);
        ExcelUtil<TrArchives> util = new ExcelUtil<TrArchives>(TrArchives.class);
        util.exportExcel(response, list, "学员档案数据");
    }

    /**
     * 获取学员档案详细信息
     */
    @PreAuthorize("@ss.hasPermi('school:archives:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(trArchivesService.selectTrArchivesById(id));
    }

    /**
     * 新增学员档案
     */
    @PreAuthorize("@ss.hasPermi('school:archives:add')")
    @Log(title = "学员档案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TrArchives trArchives)
    {
        return toAjax(trArchivesService.insertTrArchives(trArchives));
    }

    /**
     * 修改学员档案
     */
    @PreAuthorize("@ss.hasPermi('school:archives:edit')")
    @Log(title = "学员档案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TrArchives trArchives)
    {
        return toAjax(trArchivesService.updateTrArchives(trArchives));
    }

    /**
     * 删除学员档案
     */
    @PreAuthorize("@ss.hasPermi('school:archives:remove')")
    @Log(title = "学员档案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(trArchivesService.deleteTrArchivesByIds(ids));
    }
}
